package com.magic.shop.module;

import com.google.code.kaptcha.Producer;
import com.magic.shop.constants.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.ssssssss.magicapi.core.annotation.MagicModule;

import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;


@Component
@Slf4j
@MagicModule("commonModule")
public class CommonModule {

    @Autowired
    private Producer producer;


    public static String USER_LOGIN_CAPTCHA_REDIS_PREFIX=CommonConstants.USER_LOGIN_CAPTCHA;

    /**
     * 生成5位验证码
     * @return
     */
    public String createCaptchaText(){
        //生成文字验证码
        String code = producer.createText();
        return code;
    }

    public BufferedImage createCaptchaImg(String code){
        BufferedImage image = producer.createImage(code);
        return image;
    }

}
